package com.lw;

import javax.servlet.Servlet;
import java.util.HashMap;
import java.util.Map;

/**
 * 应用上下文信息
 */
public class Context {

    private String appName;
    private Map<String, Servlet> urlPatternMap = new HashMap<>();

    public Context(String appName){
        this.appName = appName;
    }

    public void addUrlPatternMap(String urlPattern,Servlet servlet){
        urlPatternMap.put(urlPattern,servlet);
    }

    public Servlet getByUrlPattern(String urlPattern){
        for (String key : urlPatternMap.keySet()) {
            if(key.contains(urlPattern)){
                return  urlPatternMap.get(key);
            }
        }
        return null;
//        return urlPatternMap.get(urlPattern);
    }

}
